package com.o2o.app.userCenter;

/**
 * 我的二手
 */
import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.o2o.app.R;

public class MineOrdActivity extends Activity {
	private static final int CLICK_RLT = -1;

	// item布局按钮
	private ArrayList<RelativeLayout> rltLists = new ArrayList<RelativeLayout>();
	/**
	 * 已发布按钮
	 */
	private RelativeLayout rlt_title02;

	/**
	 * 审核中
	 */
	private RelativeLayout rlt_title01;

	/**
	 * 已结束
	 */
	private RelativeLayout rlt_title03;

	private ImageView iv_huaxian1;
	private ImageView iv_huaxian2;
	private ImageView iv_huaxian3;

	private TextView tv_published;
	private TextView tv_audit;
	private TextView tv_over;

	/**
	 * 已发布内容
	 */
	private LinearLayout layout;

	/**
	 * 审核中内容
	 */
	private LinearLayout layout02;
	/**
	 * 已结束内容
	 */
	private LinearLayout layout03;

	/**
	 * 发布按钮
	 */
	private Button btn_publish;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.mine_ord);

		initViews();
		showView();
		showView2();
		showView3();
	}

	private void initViews() {
		rlt_title02 = (RelativeLayout) findViewById(R.id.rlt_title02);
		rlt_title02.setOnClickListener(new ClickEvent());

		rlt_title01 = (RelativeLayout) findViewById(R.id.rlt_title01);
		rlt_title01.setOnClickListener(new ClickEvent());

		rlt_title03 = (RelativeLayout) findViewById(R.id.rlt_title03);
		rlt_title03.setOnClickListener(new ClickEvent());

		iv_huaxian1 = (ImageView) findViewById(R.id.iv_huaxian1);
		iv_huaxian2 = (ImageView) findViewById(R.id.iv_huaxian2);
		iv_huaxian3 = (ImageView) findViewById(R.id.iv_huaxian3);

		tv_published = (TextView) findViewById(R.id.tv_published);
		tv_audit = (TextView) findViewById(R.id.tv_audit);
		tv_over = (TextView) findViewById(R.id.tv_over);

		// 发布按钮
		btn_publish = (Button) findViewById(R.id.btn_publish);
		btn_publish.setOnClickListener(new ClickEvent());
	}

	/**
	 * 点击事件
	 * 
	 * @author Administrator
	 * 
	 */
	class ClickEvent implements View.OnClickListener {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			switch (v.getId()) {
			case R.id.rlt_title02: {
				iv_huaxian2.setVisibility(View.VISIBLE);
				iv_huaxian1.setVisibility(View.GONE);
				iv_huaxian3.setVisibility(View.GONE);

				tv_published.setTextColor(getResources()
						.getColor(R.color.gold1));
				tv_audit.setTextColor(getResources().getColor(R.color.black));
				tv_over.setTextColor(getResources().getColor(R.color.black));

				// 点击已发布，显示发布内容
				layout.setVisibility(View.VISIBLE);
				layout02.setVisibility(View.GONE);
				layout03.setVisibility(View.GONE);

			}
				break;

			case R.id.rlt_title01: {
				iv_huaxian2.setVisibility(View.GONE);
				iv_huaxian1.setVisibility(View.VISIBLE);
				iv_huaxian3.setVisibility(View.GONE);

				tv_published.setTextColor(getResources()
						.getColor(R.color.black));
				tv_audit.setTextColor(getResources().getColor(R.color.gold1));
				tv_over.setTextColor(getResources().getColor(R.color.black));

				// 点击审核中，显示审核中内容
				layout02.setVisibility(View.VISIBLE);
				layout.setVisibility(View.GONE);
				layout03.setVisibility(View.GONE);
			}
				break;

			case R.id.rlt_title03: {
				iv_huaxian2.setVisibility(View.GONE);
				iv_huaxian1.setVisibility(View.GONE);
				iv_huaxian3.setVisibility(View.VISIBLE);

				tv_published.setTextColor(getResources()
						.getColor(R.color.black));
				tv_audit.setTextColor(getResources().getColor(R.color.black));
				tv_over.setTextColor(getResources().getColor(R.color.gold1));

				// 点击已结束，显示结束布局
				layout03.setVisibility(View.VISIBLE);
				layout02.setVisibility(View.GONE);
				layout.setVisibility(View.GONE);
			}
				break;

			case CLICK_RLT: {
				checkRltItem(v);
			}
				break;

			case R.id.btn_publish: { // 发布按钮
				Intent intent = new Intent(MineOrdActivity.this,
						MineSendTypeActivity.class);
				startActivity(intent);
				finish();
			}
				break;
			default:
				break;
			}
		}

	}

	/**
	 * 点击布局
	 */
	private void checkRltItem(View v) {
		int index = -1;
		for (int i = 0; i < 2; i++) { // 遍历选择了哪项
			if (rltLists.get(i).equals(v)) { // 为真、确定是选了哪项
				index = i;
			}
		}

		if (index >= 0) { // 个人中心点击二手详情，跳到二手信息编辑界面
			Intent intent = new Intent(MineOrdActivity.this,
					MinePublishInfoActivity.class);
			startActivity(intent);

		}
	}

	/**
	 * 显示已发布
	 */
	private void showView() {
		layout = (LinearLayout) findViewById(R.id.lly_all_content01);
		// layout.removeAllViews();
		layout.setVisibility(View.VISIBLE);

		for (int i = 0; i < 2; i++) {
			LinearLayout child = (LinearLayout) LayoutInflater.from(
					MineOrdActivity.this).inflate(R.layout.mine_ord_item, null);
			child.setId(i);

			RelativeLayout rlt_item = (RelativeLayout) child
					.findViewById(R.id.rlt_item);
			rlt_item.setId(CLICK_RLT);
			rlt_item.setOnClickListener(new ClickEvent());
			rltLists.add(rlt_item);

			layout.addView(child);
		}
	}

	/**
	 * 显示审核中
	 */
	private void showView2() {
		layout02 = (LinearLayout) findViewById(R.id.lly_all_content02);
		// layout.removeAllViews();
		layout02.setVisibility(View.VISIBLE);

		for (int i = 0; i < 2; i++) {
			LinearLayout child = (LinearLayout) LayoutInflater.from(
					MineOrdActivity.this).inflate(R.layout.mine_ord_item, null);

			layout02.addView(child);
		}
	}

	/**
	 * 显示审核中
	 */
	private void showView3() {
		layout03 = (LinearLayout) findViewById(R.id.lly_all_content03);
		// layout.removeAllViews();
		layout03.setVisibility(View.GONE);

		for (int i = 0; i < 2; i++) {
			LinearLayout child = (LinearLayout) LayoutInflater.from(
					MineOrdActivity.this)
					.inflate(R.layout.mine_over_item, null);

			layout03.addView(child);
		}
	}
}
